﻿#include "PriorityThread.h"

namespace Common {

	PriorityThread::PriorityThread(QObject* parent /*= nullptr*/, std::function<void()> runFunc /*= NULL*/) :
		QThread(parent),
		m_runFunc(runFunc)
	{

	}

	PriorityThread::~PriorityThread()
	{

	}

	void PriorityThread::start(QThread::Priority priority /*= InheritPriority*/)
	{
		QThread::start(priority);
	}

	void PriorityThread::stop(unsigned long time)
	{
		if (this->isRunning())
		{
			this->quit();
			this->wait(time);
		}
	}

	void PriorityThread::run()
	{
		if (m_runFunc)
		{
			this->m_runFunc();
		}
	}

	void PriorityThread::setRunFunc(std::function<void()> runFunc)
	{
		this->m_runFunc = runFunc;
	}

}//namespace Common 
